package samples
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import marcel.core.Plugin;
	import marcel.debug.*;
	import marcel.display.screen.ScreenAlignTypes;
	import marcel.display.View;
	import marcel.events.FileLoaderEvent;
	import marcel.external.FileLoader;
	import marcel.external.FileType;
	import marcel.utils.BitmapUtils;	
	
	public class BitmapUtilsSample extends View
	{
		public function BitmapUtilsSample() 
		{
			var fl:FileLoader = new FileLoader(FileType.IMAGE);
			fl.addEventListener(FileLoaderEvent.COMPLETE, onImage)
			fl.load(Plugin.plugin.config.getVar("imagedir") + "tween_test.jpg");
		}
		
		private function onImage(e:FileLoaderEvent):void 
		{
			// show default image
			addChild(e.content);
			
			// get BitmapData
			var bd:BitmapData = BitmapUtils.getBitmapData(e.content);
			
			// crop
			var cropped:BitmapData = BitmapUtils.crop(bd, new Rectangle(20, 50, 80, 80));
			addChildWithProps(new Bitmap(cropped), {x:350});			
			
			// resize with sampling (needed if ratio < 0.5)
			var resized:BitmapData = BitmapUtils.resize(bd, 100, 100, true, true, true);
			addChildWithProps(new Bitmap(resized), {x:500});
			
			// resize wihtout sampling
			var resized2:BitmapData = BitmapUtils.resize(bd, 100, 100);
			addChildWithProps(new Bitmap(resized2), {x:500, y:110});
			
			// fit
			// the image smallest side will be set as requested, the image ratio will be kept
			// so you need to specify th alignment to set the image part to display
			// => use a constanr of the class ScreenAlignTypes
			// => utiliser une constante de la classe ScreenAlignTypes
			var fitted:BitmapData = BitmapUtils.fit(bd, 100, 150, ScreenAlignTypes.BOTTOM_RIGHT);
			addChildWithProps(new Bitmap(fitted), {x:620});
			
			// rescale
			var scaled:BitmapData = BitmapUtils.rescale(bd, .6);
			addChildWithProps(new Bitmap(scaled), {x:800});
		}
	}
}